var uploadTask = null
Page({
  data:{
    schema: [],
    title: '',
    result: '',
    zh:'',
    options: {},
    apiType: '',
    remark: '',
    webUrl: '',
    apiName: '',
    file:null
  },
  onLoad(options) {
    this.setData({
      apiType: options.zh,
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })

    if (wx.onThemeChange) {
      wx.onThemeChange(({theme}) => {
        this.setData({theme})
      })
    }
  },
  chooseFile() {
    wx.chooseMedia({
      count: 1,
      success:(res)=>{
        this.setData({
          file:res.tempFiles[0],
          result:res
        })
      }
    })
  },
  uploadFile() {
    console.log(this.data.file)
    uploadTask = wx.uploadFile({
      filePath: this.data.file.tempFilePath,
      name: 'file',
      url: 'http://10.10.45.95:8080/upload',
      complete:(res)=>{
        this.setData({
          result:res,
          apiName:'wx.uploadFile'
        })
      }
    })
    uploadTask.onHeadersReceived((res)=>{
      console.log(res)
      this.setData({
        result:res,
        apiName:'UploadTask.onHeadersReceived'
      })
    })
    uploadTask.onProgressUpdate((res)=>{
      console.log(res)
      this.setData({
        result:res,
        apiName:'UploadTask.onProgressUpdate'
      })
    })
  },
  abort(){
    uploadTask.abort()
  },
  offHeadersReceived() {
    uploadTask.offHeadersReceived()
  },
  offProgressUpdate() {
    uploadTask.offProgressUpdate()
  }
})
